package com.xgggh.redpack.domain.redpack;


import androidx.databinding.BaseObservable;
import androidx.databinding.Bindable;
import android.os.Parcel;
import android.os.Parcelable;

import com.xgggh.redpack.BR;
import com.xgggh.redpack.domain.auth.Profile;

import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.logging.SimpleFormatter;

public class Pack  extends BaseObservable implements Parcelable {
    private Long id;

    private String accountId;

    /** 红包分类
     * {@link com.xgggh.redpack.domain.category.CategoryItem}
     */
    private int category;

    private double fee;

    private double amount;

    private String scope;

    private String targetId;

    private String message;

    private String address="";

    private double latitude;

    private double longitude;
    //领取限制 时间，地点等
    private String useLimited;

    private Profile profile;

    private Date created;

    private Date updated;

    private Date deleted;

    //DecimalFormat decimalFormat = new DecimalFormat("#.###");

    public String getUseLimited() {
        return useLimited;
    }

    public void setUseLimited(String useLimited) {
        this.useLimited = useLimited;
    }

    public Profile getProfile() {
        return profile;
    }

    public void setProfile(Profile profile) {
        this.profile = profile;
    }

    @Bindable
    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
        notifyPropertyChanged(BR.address);
    }
    @Bindable
    public double getLatitude() {
        return latitude;
    }

    public void setLatitude(double latitude) {
        this.latitude = latitude;
        notifyPropertyChanged(BR.latitude);
    }
    @Bindable
    public double getLongitude() {
        return longitude;
    }

    public void setLongitude(double longitude) {
        this.longitude = longitude;
        notifyPropertyChanged(BR.longitude);
    }

    public Pack(Long id, String accountId, int category, double fee, double amount, String scope, String targetId, String message, Date created, Date updated, Date deleted) {
        this.id = id;
        this.accountId = accountId;
        this.category = category;
        this.fee = fee;
        this.amount = amount;
        this.scope = scope;
        this.targetId = targetId;
        this.message = message;
        this.created = created;
        this.updated = updated;
        this.deleted = deleted;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Pack() {
        super();
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getAccountId() {
        return accountId;
    }

    public void setAccountId(String accountId) {
        this.accountId = accountId;
    }


    public int getCategory() {
        return category;
    }

    public void setCategory(int category) {
        this.category = category;
    }

    @Bindable
    public double getFee() {
        return  fee; //decimalFormat.format(fee);
    }

    public void setFee(double fee) {
        this.fee = fee;
        notifyPropertyChanged(BR.fee);
    }

    @Bindable
    public double getAmount() {
        return amount;
    }

    public void setAmount(double amount) {
        notifyPropertyChanged(BR.amount);
        this.amount = amount;
    }

    public String getScope() {
        return scope;
    }

    public void setScope(String scope) {
        this.scope = scope;
    }

    public String getTargetId() {
        return targetId;
    }

    public void setTargetId(String targetId) {
        this.targetId = targetId;
    }

    public Date getCreated() {
        return created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    public Date getUpdated() {
        return updated;
    }

    public void setUpdated(Date updated) {
        this.updated = updated;
    }

    public Date getDeleted() {
        return deleted;
    }

    public void setDeleted(Date deleted) {
        this.deleted = deleted;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeValue(this.id);
        dest.writeString(this.accountId);
        dest.writeInt(this.category);
        dest.writeDouble(this.fee);
        dest.writeDouble(this.amount);
        dest.writeString(this.scope);
        dest.writeString(this.targetId);
        dest.writeString(this.message);
        dest.writeString(this.address);
        dest.writeDouble(this.latitude);
        dest.writeDouble(this.longitude);
        dest.writeString(this.useLimited);
        dest.writeParcelable(this.profile, flags);
        dest.writeLong(this.created != null ? this.created.getTime() : -1);
        dest.writeLong(this.updated != null ? this.updated.getTime() : -1);
        dest.writeLong(this.deleted != null ? this.deleted.getTime() : -1);
    }

    protected Pack(Parcel in) {
        this.id = (Long) in.readValue(Long.class.getClassLoader());
        this.accountId = in.readString();
        this.category = in.readInt();
        this.fee = in.readDouble();
        this.amount = in.readDouble();
        this.scope = in.readString();
        this.targetId = in.readString();
        this.message = in.readString();
        this.address = in.readString();
        this.latitude = in.readDouble();
        this.longitude = in.readDouble();
        this.useLimited = in.readString();
        this.profile = in.readParcelable(Profile.class.getClassLoader());
        long tmpCreated = in.readLong();
        this.created = tmpCreated == -1 ? null : new Date(tmpCreated);
        long tmpUpdated = in.readLong();
        this.updated = tmpUpdated == -1 ? null : new Date(tmpUpdated);
        long tmpDeleted = in.readLong();
        this.deleted = tmpDeleted == -1 ? null : new Date(tmpDeleted);
    }

    public static final Creator<Pack> CREATOR = new Creator<Pack>() {
        @Override
        public Pack createFromParcel(Parcel source) {
            return new Pack(source);
        }

        @Override
        public Pack[] newArray(int size) {
            return new Pack[size];
        }
    };
}